$(function() {
	download.run();
});

var download = {
	run : function() {
		this.__init__();
		this._start_();
		this._bind_events();
	},

	__init__ : function() {
		
		this.itemUrl = "";
		this.title = "";
		this.vdInstalled = vd.check();
		this.vcClient = false;
		
	},

	_start_ : function() {
	},

	_bind_events : function() {
		$(".download_btn").live('click', function() {
			download.itemUrl = $(this).attr("itemUrl");
			download.title = $(this).attr("itemTitle");
			//alert(download.title);
			var website = $(this).attr("website");
			if (website == "Moviefone" || website == "Imdb") {
				this.$alertDialog = $(".donwolad-alert-no-support");
				this.$alertDialog.dialog('open');
				return false;
			} 
			if (!download.vdInstalled) {
				var ua = navigator.userAgent;
				if (ua.indexOf('Mac') >= 0) {
					this.$alertDialog = $(".donwolad-alert-mac");
				} else {
					this.$alertDialog = $(".donwolad-alert");
				}
				//alert(this.$alertDialog.html());
				this.$alertDialog.dialog({
					submit : function() {
						vd.keep();
						_gaq.push([ '_trackEvent', 'Movice', 'Download', download.itemUrl ]);
						vd.go(download.itemUrl, download.title);
						download.vdInstalled = true;
					}
				});
				this.$alertDialog.dialog('open');
			} else {
				_gaq.push([ '_trackEvent', 'Movice', 'Download', download.itemUrl ]);
				vd.go(download.itemUrl, download.title);
			}
			
			return false;
		});
	},
	/*专供vc调用*/
	vc_download : function(){
		//alert('hi');
		if (vd.check()) {
			return;
		}else{
			vd.keep();
			//alert('hi');
		}
		
	}

};
